package com.jsz.peini.controller.app;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jsz.peini.bean.codes.SystemSeller;
import com.jsz.peini.bean.order.OrderInfo;
import com.jsz.peini.bean.order.OrderSeller;
import com.jsz.peini.bean.order.OrderSellerExample;
import com.jsz.peini.bean.search.SearchHot;
import com.jsz.peini.bean.search.SearchHotExample;
import com.jsz.peini.bean.seller.SellerDiscount;
import com.jsz.peini.bean.seller.SellerInfo;
import com.jsz.peini.bean.seller.SellerJoin;
import com.jsz.peini.bean.seller.SellerJudge;
import com.jsz.peini.bean.seller.SellerJudgeExample;
import com.jsz.peini.bean.seller.SellerOperating;
import com.jsz.peini.bean.seller.SellerOperatingExample;
import com.jsz.peini.bean.task.TaskInfo;
import com.jsz.peini.bean.user.UserInfo;
import com.jsz.peini.bean.user.UserJudge;
import com.jsz.peini.bean.user.UserSms;
import com.jsz.peini.common.constants.Constants;
import com.jsz.peini.common.util.CommonUtils;
import com.jsz.peini.common.util.PeiniUtils;
import com.jsz.peini.mapper.order.OrderInfoMapper;
import com.jsz.peini.mapper.order.OrderSellerMapper;
import com.jsz.peini.mapper.search.SearchHotMapper;
import com.jsz.peini.mapper.seller.SellerDiscountMapper;
import com.jsz.peini.mapper.seller.SellerInfoMapper;
import com.jsz.peini.mapper.seller.SellerJudgeMapper;
import com.jsz.peini.mapper.seller.SellerOperatingMapper;
import com.jsz.peini.mapper.task.TaskInfoMapper;
import com.jsz.peini.mapper.user.UserAccountMapper;
import com.jsz.peini.mapper.user.UserInfoMapper;
import com.jsz.peini.mapper.user.UserJudgeMapper;
import com.jsz.peini.mapper.user.UserSmsMapper;
import com.jsz.peini.service.codes.SystemDistrictService;
import com.jsz.peini.service.order.OrderInfoService;
import com.jsz.peini.service.payment.PaymentInfoService;
import com.jsz.peini.service.seller.SellerDiscountService;
import com.jsz.peini.service.seller.SellerInfoService;
import com.jsz.peini.service.seller.SellerJoinService;
import com.jsz.peini.service.seller.SellerJudgeService;
import com.jsz.peini.service.user.UserInfoService;
import com.jsz.peini.service.user.UserJudgeService;
import com.jsz.peini.sms.SmsSend;

@Controller
public class SellerInfoControllor {
	private static final Logger logger = LoggerFactory.getLogger(SellerInfoControllor.class);
	@Autowired
	private SellerInfoService sellerInfoService;

	@Autowired
	private SystemDistrictService SystemDistrictService;

	@Autowired
	private SellerJoinService sellerJoinService;

	@Autowired
	private SellerJudgeService sellerJudgeService;

	@Autowired
	private UserJudgeService userJudgeService;

	@Autowired
	private UserInfoService userInfoService;

	@Autowired
	private PaymentInfoService paymentInfoService;

	@Autowired
	private OrderInfoService orderInfoService;
	@Resource
	private OrderInfoMapper orderInfoMapper;
	@Resource
	private UserAccountMapper userAccountMapper;
	@Resource
	private SearchHotMapper searchHotMapper;
	@Resource
	private SellerInfoMapper sellerInfoMapper;
	@Resource
	private OrderSellerMapper orderSellerMapper;
	@Resource
	private UserSmsMapper userSmsMapper;
	@Resource
	private SellerJudgeMapper sellerJudgeMapper;
	@Resource
	private UserJudgeMapper userJudgeMapper;
	@Resource
	private UserInfoMapper userInfoMapper;
	@Resource
	private TaskInfoMapper taskInfoMapper;
	@Resource
	private SellerDiscountMapper sellerDiscountMapper;
	@Resource
	private SellerOperatingMapper sellerOperatingMapper;
	@Resource
	private SellerDiscountService sellerDiscountService;

	/**
	 * 获取商家信息
	 * 
	 * @param id
	 *            店铺id
	 * @author zq
	 */
	@RequestMapping(value = "/getSellerInfo")
	@ResponseBody
	public Object getSellerInfo(HttpServletRequest request, Integer id,
			String xpoint, String ypoint,
			@RequestParam(value="type",required=false) Integer type,//1通知；不传为商家列表
			@RequestParam(value="orderId",required=false) Long orderId
			) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			if(id == null || id == 0){
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "参数缺失");
				return infoMap;
			}
			
			int linkType = 1;//商家详情
			
			if(type == null){
				linkType = 1;
			}else{
				OrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
				if(orderInfo.getOrderStatus() == 1){//跳转评价
					linkType = 2;
				}else if(orderInfo.getOrderStatus() == 2){//商家详情
					linkType = 1;
				}
			}
			
			if(linkType == 1){
				Date d = new Date();
				SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
				String dateStr = sdf.format(d);
				SellerInfo sellerInfo = sellerInfoService.selectById(id);
				
				String styleStr = "<style>img{height: auto;width: 100%;}</style>";
				sellerInfo.setInformation(styleStr + sellerInfo.getInformation());
				
				//SellerInfo sellerInfo = sellerInfoMapper.selectByPrimaryKey(id);
				// 计算距离
				sellerInfo.setDistance(CommonUtils.contrastMap(xpoint, ypoint,
						sellerInfo.getXpoint(), sellerInfo.getYpoint()));
				// 计算价格
				sellerInfo.setPrice(sellerInfo.getPrice() / 100);
				// 设置优惠券信息
				List<HashMap<String, Object>> couponList = sellerInfoService.getSellerCoupons(id);
				if (couponList.size() > 0) {
					StringBuffer str = new StringBuffer();
					for (HashMap<String, Object> couponMap : couponList) {
						str.append(couponMap.get("couponName") + ",");
					}
					sellerInfo.setCouponMj(str.toString().substring(0,
							str.length() - 1));
				}
				sellerInfo.setLabelsName(PeiniUtils.yetaiMap.get(sellerInfo.getLabelsId().toString()).getCodesName());
				// 设置金币折扣信息
				SellerDiscount sellerDiscount = new SellerDiscount();
				sellerDiscount.setSellerInfoId(id);
				sellerDiscount.setNowNum(CommonUtils.getWeekNum());
				sellerDiscount.setNowTime(dateStr);
				SellerDiscount discountMap = sellerInfoService.getSellerDiscount(sellerDiscount);
				if (discountMap != null) {
					String str = "";
					if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
						BigDecimal goldNum = new BigDecimal(discountMap.getGoldNum());
						goldNum = goldNum.divide(new BigDecimal(10));
						str += "金币"+goldNum+"折，";
						//str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
					}
					if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
						BigDecimal wxNum = new BigDecimal(discountMap.getWeixinNum());
						wxNum = wxNum.divide(new BigDecimal(10));
						str += "微信"+wxNum+"折，";
						//str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
					}
					if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
						BigDecimal aliNum = new BigDecimal(discountMap.getZfbNum());
						aliNum = aliNum.divide(new BigDecimal(10));
						str += "支付宝"+aliNum+"折，";
						//str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
					}
					if(str.endsWith("，")){
						str = str.substring(0, str.length()-1);
					}
					sellerInfo.setCouponJb(str);
					/*sellerInfo.get(i).put("countJB",str);
				sellerInfo.setCouponJb("金币买单"
						+ CommonUtils.doubleTrans((double) discountMap
								.getGoldNum() / 100)
						+ "折,微信买单"
						+ CommonUtils.doubleTrans((double) discountMap
								.getWeixinNum() / 100)
						+ "折,支付宝买单"
						+ CommonUtils.doubleTrans((double) discountMap
								.getZfbNum() / 100) + "折");*/
				}
				// 获取商家图片列表
				List<HashMap<String, Object>> imageList = sellerInfoService.getSellerImages(id);
				sellerInfo.setImageList(imageList);
				
				net.sf.json.JSONObject obj = net.sf.json.JSONObject.fromObject(sellerInfo);
				SystemSeller systemSeller = PeiniUtils.yetaiMap.get(sellerInfo.getSellerType().toString());
				String sellerBigName = systemSeller.getCodesName();
				String imgSrc = systemSeller.getImageSrc();
				
				obj.remove("smsText");
				obj.remove("accname");
				obj.remove("accpass");
				obj.remove("accmail");
				obj.remove("accmobile");
				obj.remove("cityCode");
				obj.remove("companyId");
				obj.remove("distid");
				obj.remove("districtCode");
				obj.remove("labelsId");
				obj.remove("labelsName");
				obj.remove("listNum");
				obj.remove("provinceid");
				obj.remove("searchWord");
				obj.remove("searchType");
				obj.remove("sellerImg");
				obj.remove("sellerKey");
				obj.remove("sellerType");
				obj.remove("sellerstatus");
				obj.remove("smsmobile");
				obj.remove("sort");
				obj.remove("status");
				obj.remove("weathersms");
				obj.remove("status");
				obj.remove("sellerBigName");
				
				obj.put("sellerBigName", sellerBigName);
				obj.put("sellerTypeImg", imgSrc);
				obj.put("shareTitle", "我正在看陪你"+sellerInfo.getSellerName()+"店铺，口碑非常棒，分享给你>>>");
				
				SellerOperatingExample sExample = new SellerOperatingExample();
				sExample.createCriteria().andSellerInfoIdEqualTo(sellerInfo.getId());
				sExample.setOrderByClause("start_num asc");
				List<SellerOperating> opList = sellerOperatingMapper.selectByExample(sExample);
				
				HashMap<Integer, SellerOperating> opMap = new HashMap<Integer, SellerOperating>();
				for (SellerOperating op : opList) {
					if(!opMap.containsKey(op.getStartNum())){
						opMap.put(op.getStartNum(), op);
					}
				}
				
				List<LinkedHashMap<String, Object>> startList = new ArrayList<LinkedHashMap<String, Object>>();
				Set<Integer> keys = opMap.keySet();
				Iterator<Integer> it = keys.iterator();  
				while (it.hasNext()) {  
					Integer key = it.next();  
					
					SellerOperating op = opMap.get(key);
					Integer startNum = op.getStartNum();
					Integer endNum = op.getEndNum();
					
					LinkedHashMap<String, Object> keyMap = new LinkedHashMap<String, Object>();
					
					String weekNum = PeiniUtils.getWeekDesc(startNum);
					if(endNum-startNum == 0){
						
					}else if(endNum-startNum == 1){
						weekNum += "、";
						weekNum += PeiniUtils.getWeekDesc(endNum);
					}else {
						weekNum += "至";
						weekNum += PeiniUtils.getWeekDesc(endNum);
					}
					
					keyMap.put("weekNum", weekNum);
					
					List<LinkedHashMap<String, Object>> oList = new ArrayList<LinkedHashMap<String, Object>>();
					
					for (SellerOperating p : opList) {
						if(p.getStartNum() == startNum && p.getEndNum() == endNum){
							LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
							map.put("oDesc", p.getTimeDecs());
							map.put("oTime", p.getStartTime()+"-"+p.getEndTime());
							oList.add(map);
						}
					}
					
					keyMap.put("opList", oList);
					startList.add(keyMap);
				} 
				
				obj.put("opTimes",startList);
				
				/*List<LinkedHashMap<String, Object>> sellerdiscount=sellerOperatingMapper.getSellerOperatingBySellerId(sellerInfo.getId());
				for (int i = 0; i < sellerdiscount.size(); i++) {
					SellerOperating sellerOperating=new SellerOperating();
					sellerOperating.setId(sellerInfo.getId());
					if (sellerdiscount.get(i).get("startNum")!=null) {
						sellerOperating.setStartNum(Integer.parseInt(sellerdiscount.get(i).get("startNum").toString()));
					}if(sellerdiscount.get(i).get("endNum")!=null){
						sellerOperating.setEndNum(Integer.parseInt(sellerdiscount.get(i).get("endNum").toString()));
					}
					List<LinkedHashMap<String, Object>> times=sellerOperatingMapper.getSellerOperatingBySellerIdAndNum(sellerOperating);
					sellerdiscount.get(i).put("times",times);
					if (sellerdiscount.get(i).get("startNum").toString().equals("1")) {sellerdiscount.get(i).put("startNum","星期一");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("2")) {sellerdiscount.get(i).put("startNum","星期二");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("3")) {sellerdiscount.get(i).put("startNum","星期三");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("4")) {sellerdiscount.get(i).put("startNum","星期四");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("5")) {sellerdiscount.get(i).put("startNum","星期五");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("6")) {sellerdiscount.get(i).put("startNum","星期六");
					}else if (sellerdiscount.get(i).get("startNum").toString().equals("7")) {sellerdiscount.get(i).put("startNum","星期日");
					}else {sellerdiscount.get(i).put("startNum","");
					}
					if (sellerdiscount.get(i).get("endNum").toString().equals("1")) {sellerdiscount.get(i).put("endNum","星期一");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("2")) {sellerdiscount.get(i).put("endNum","星期二");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("3")) {sellerdiscount.get(i).put("endNum","星期三");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("4")) {sellerdiscount.get(i).put("endNum","星期四");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("5")) {sellerdiscount.get(i).put("endNum","星期五");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("6")) {sellerdiscount.get(i).put("endNum","星期六");
					}else if (sellerdiscount.get(i).get("endNum").toString().equals("7")) {sellerdiscount.get(i).put("endNum","星期日");
					}else {sellerdiscount.get(i).put("endNum","");
					}
					if(sellerdiscount.get(i).get("startTime")==null){sellerdiscount.get(i).put("startTime","");
					}
					if(sellerdiscount.get(i).get("endTime")==null){sellerdiscount.get(i).put("endTime","");
					}
					
				}
				obj.put("discount",sellerdiscount);*/
				if(StringUtils.isNotBlank(sellerInfo.getCouponJb())){
					obj.put("shareContent", "全场"+sellerInfo.getCouponJb()+"，地址在"+sellerInfo.getSellerAddress()+"，跟我一起GOGOGO~");
				}else{
					obj.put("shareContent", "地址在"+sellerInfo.getSellerAddress()+"，跟我一起GOGOGO~");
				}
				infoMap.put("sellerInfo", obj);
				
				infoMap.put("resultCode", Constants.SUCCESS);
				infoMap.put("resultDesc", "成功");
			}else{
				SellerInfo sellerInfo = sellerInfoMapper.selectByPrimaryKey(id);
				net.sf.json.JSONObject obj = new net.sf.json.JSONObject();
				obj.put("sellerName", sellerInfo.getSellerName());
				infoMap.put("sellerInfo", obj);
				
				infoMap.put("resultCode", Constants.SUCCESS_SHOP);
				infoMap.put("resultDesc", "成功");
			}
			
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}

	/**
	 * 商家筛选接口
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getSellerInfoBySellerInfo")
	@ResponseBody
	public Object getSellerInfoBySellerInfo(HttpServletRequest request,
			SellerInfo sellInfo, int pageNow, int pageSize) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			if (sellInfo.getDistrictCode() != null) {
				SystemDistrictService.updateDistrict(sellInfo.getDistrictCode().toString());
			}
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			String dateStr = sdf.format(d);
			if (sellInfo.getDistance() == null) {
				PageHelper.startPage(pageNow, pageSize);
				List<LinkedHashMap<String, Object>> sellerInfo = sellerInfoService.selectBySellerInfo(sellInfo);
				for (int i = 0; i < sellerInfo.size(); i++) {
					/*int distance = CommonUtils.contrastMap(
							sellInfo.getXpoint(), sellInfo.getYpoint(),
							(String) sellerInfo.get(i).get("xpoint"),
							(String) sellerInfo.get(i).get("ypoint"));*/
					sellerInfo.get(i).put("districtName", PeiniUtils.distMap.get(sellerInfo.get(i).get("districtCode")).getPlcaeName());
					sellerInfo.get(i).remove("xpoint");
					sellerInfo.get(i).remove("ypoint");
					sellerInfo.get(i).put("price",
							(int) (sellerInfo.get(i).get("price")) / 100);
					//sellerInfo.get(i).put("distance", distance);
					Double distance  = ((double)sellerInfo.get(i).get("juli"));
					sellerInfo.get(i).put("distance", distance.intValue());
					sellerInfo.get(i).put("labels_name", PeiniUtils.yetaiMap.get(sellerInfo.get(i).get("labels_id").toString()).getCodesName());
					// 设置优惠券信息
					List<HashMap<String, Object>> couponList = sellerInfoService
							.getSellerCoupons(Integer.parseInt(sellerInfo
									.get(i).get("id").toString()));
					if (couponList.size() > 0) {
						StringBuffer str = new StringBuffer();
						for (HashMap<String, Object> couponMap : couponList) {
							str.append(couponMap.get("couponName") + ",");
						}
						sellerInfo.get(i).put("countMJ",
								str.toString().substring(0, str.length() - 1));
					}else{
						sellerInfo.get(i).put("countMJ","");
					}
					// 设置金币折扣信息
					SellerDiscount sellerDiscount = new SellerDiscount();
					sellerDiscount.setSellerInfoId(Integer.parseInt(sellerInfo
							.get(i).get("id").toString()));
					sellerDiscount.setNowNum(CommonUtils.getWeekNum());
					sellerDiscount.setNowTime(dateStr);
					SellerDiscount discountMap = sellerInfoService.getSellerDiscount(sellerDiscount);
					if (discountMap != null) {
						String str = "";
						if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
							BigDecimal goldNum = new BigDecimal(discountMap.getGoldNum());
							goldNum = goldNum.divide(new BigDecimal(10));
							str += "金币"+goldNum+"折，";
							//str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
						}
						if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
							BigDecimal wxNum = new BigDecimal(discountMap.getWeixinNum());
							wxNum = wxNum.divide(new BigDecimal(10));
							str += "微信"+wxNum+"折，";
							//str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
						}
						if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
							BigDecimal aliNum = new BigDecimal(discountMap.getZfbNum());
							aliNum = aliNum.divide(new BigDecimal(10));
							str += "支付宝"+aliNum+"折，";
							//str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
						}
						/*if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
							str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
						}
						if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
							str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
						}
						if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
							str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
						}*/
						if(str.endsWith("，")){
							str = str.substring(0, str.length()-1);
						}
						sellerInfo.get(i).put("countJB",str);
					} else {
						sellerInfo.get(i).put("countJB", "");
					}
				}
				infoMap.put("resultCode", Constants.SUCCESS);
				infoMap.put("resultDesc", "成功");
				infoMap.put("sellerInfo", sellerInfo);
			} else {// 按照距离
				PageHelper.startPage(pageNow, pageSize);
				List<LinkedHashMap<String, Object>> sellerInfo = sellerInfoService.selectBySellerInfo(sellInfo);
				List<LinkedHashMap<String, Object>> sellerInfoDistance = new ArrayList<LinkedHashMap<String, Object>>();
				List<LinkedHashMap<String, Object>> sellerInfoDistanceList = new ArrayList<LinkedHashMap<String, Object>>();
				for (int i = 0; i < sellerInfo.size(); i++) {
					/*int distance = CommonUtils.contrastMap(
							sellInfo.getXpoint(), sellInfo.getYpoint(),
							(String) sellerInfo.get(i).get("xpoint"),
							(String) sellerInfo.get(i).get("ypoint"));
					if (distance <= sellInfo.getDistance()) {*/
						sellerInfo.get(i).remove("xpoint");
						sellerInfo.get(i).remove("ypoint");
						sellerInfo.get(i).put("price",
								(int) (sellerInfo.get(i).get("price")) / 100);
						Double distance  = ((double)sellerInfo.get(i).get("juli"));
						sellerInfo.get(i).put("distance", distance.intValue());
						//sellerInfo.get(i).put("distance", (int)sellerInfo.get(i).get("juli"));
						sellerInfo.get(i).put("districtName", PeiniUtils.distMap.get(sellerInfo.get(i).get("districtCode")).getPlcaeName());
						sellerInfo.get(i).put("labels_name", PeiniUtils.yetaiMap.get(sellerInfo.get(i).get("labels_id").toString()).getCodesName());
						//logger.info("--------------------------"+PeiniUtils.yetaiMap.get(sellerInfo.get(i).get("labels_id").toString()).getCodesName());
						// 设置优惠券信息
						int sellerId = Integer.parseInt(sellerInfo.get(i)
								.get("id").toString());
						List<HashMap<String, Object>> couponList = sellerInfoService.getSellerCoupons(sellerId);
						if (couponList.size() > 0) {
							StringBuffer str = new StringBuffer();
							for (HashMap<String, Object> couponMap : couponList) {
								str.append(couponMap.get("couponName") + ",");
							}
							sellerInfo.get(i).put(
									"countMJ",
									str.toString().substring(0,
											str.length() - 1));
						} else {
							sellerInfo.get(i).put("countMJ", "");
						}
						// 设置金币折扣信息
						SellerDiscount sellerDiscount = new SellerDiscount();
						sellerDiscount.setSellerInfoId(Integer
								.parseInt(sellerInfo.get(i).get("id")
										.toString()));
						sellerDiscount.setNowNum(CommonUtils.getWeekNum());
						sellerDiscount.setNowTime(dateStr);
						SellerDiscount discountMap = sellerInfoService
								.getSellerDiscount(sellerDiscount);
						if (discountMap != null) {
							String str = "";
							if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
								BigDecimal goldNum = new BigDecimal(discountMap.getGoldNum());
								goldNum = goldNum.divide(new BigDecimal(10));
								str += "金币"+goldNum+"折，";
								//str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
							}
							if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
								BigDecimal wxNum = new BigDecimal(discountMap.getWeixinNum());
								wxNum = wxNum.divide(new BigDecimal(10));
								str += "微信"+wxNum+"折，";
								//str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
							}
							if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
								BigDecimal aliNum = new BigDecimal(discountMap.getZfbNum());
								aliNum = aliNum.divide(new BigDecimal(10));
								str += "支付宝"+aliNum+"折，";
								//str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
							}
							/*if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
								str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
							}
							if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
								str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
							}
							if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
								str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
							}*/
							if(str.endsWith("，")){
								str = str.substring(0, str.length()-1);
							}
							sellerInfo.get(i).put("countJB",str);
						} else {
							sellerInfo.get(i).put("countJB", "");
						}
						sellerInfoDistance.add(sellerInfo.get(i));
					}
				//}
				/*int sizeTotle = sellerInfoDistance.size();
				if (sellerInfoDistance.size() <= ((pageNow - 1) * pageSize + pageSize)) {
					sizeTotle = sellerInfoDistance.size();
				} else {
					sizeTotle = ((pageNow - 1) * pageSize + pageSize);
				}
				for (int i = (pageNow - 1) * pageSize; i < sizeTotle; i++) {
					sellerInfoDistanceList.add(sellerInfoDistance.get(i));
				}*/
				infoMap.put("resultCode", Constants.SUCCESS);
				infoMap.put("resultDesc", "成功");
				infoMap.put("sellerInfo", sellerInfoDistance);
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}

	/**
	 * 商家业态列表
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getSellerCodesBySellerCodes")
	@ResponseBody
	public Object getSellerCodesBySellerCodes(HttpServletRequest request) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			JSONArray array = new JSONArray();
	        HashMap<Object, SystemSeller> map = PeiniUtils.yetaiMap;
	        for (Object o : map.keySet()) {
				SystemSeller ss = map.get(o);
				if(ss.getCodesSmalltype() == 0){
					JSONObject obj = new JSONObject();
					if(ss.getCodesOrder()!= null && ss.getCodesOrder() == 1){
						obj.put("id", "");
					}else{
						obj.put("id", ss.getId().toString());
					}
					
					obj.put("name", ss.getCodesName());
					obj.put("imgSrc", ss.getImageSrc());
					
					JSONArray arr = new JSONArray();
					for (Object o2 : map.keySet()) {
						SystemSeller ss2 = map.get(o2);
						if(ss2.getCodesSmalltype() != 0 && ss2.getCodesBigtype().equals(ss.getCodesBigtype())){
							JSONObject obj2 = new JSONObject();
							obj2.put("id", ss2.getId().toString());
							obj2.put("name", ss2.getCodesName());
							arr.add(obj2);
						}
					}
					obj.put("subData", arr);
					
					array.add(obj);
				}
			}
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
			infoMap.put("sellerCodes", array);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}

	/**
	 * 模糊搜索商家信息
	 * 
	 * @param searchWord
	 *            关键字,xpoint x坐标,ypoint y坐标
	 * @author zq
	 */
	@RequestMapping(value = "/searchFastSeller")
	@ResponseBody
	public Object searchFastSeller(HttpServletRequest request,
			SellerInfo sellerInfo) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			List<SellerInfo> sellerAllList = new ArrayList<SellerInfo>();
			List<SellerInfo> mapList = sellerInfoService.selectListBySearch(sellerInfo);
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			String dateStr = sdf.format(d);
			for (SellerInfo sellermap : mapList) {
				if(sellermap.getListNum() == 0){
					continue;
				}
				sellerAllList.add(sellermap);
			}

			// 默认最多展示条数
			Page<?> page = PageHelper.startPage(1, 20);
			List<SellerInfo> sellerList = sellerInfoService
					.selectBySearch(sellerInfo);
			for (SellerInfo seller : sellerList) {
				// 计算距离
				seller.setDistance(CommonUtils.contrastMap(
						sellerInfo.getXpoint(), sellerInfo.getYpoint(),
						seller.getXpoint(), seller.getYpoint()));
				// 计算价格
				seller.setPrice(seller.getPrice() / 100);
				// 设置类型为商家
				seller.setSearchType(Constants.SELLER_SEARCH_SELLER);
				// 设置优惠券信息
				List<HashMap<String, Object>> couponList = sellerInfoService
						.getSellerCoupons(seller.getId());
				if (couponList.size() > 0) {
					StringBuffer str = new StringBuffer();
					for (HashMap<String, Object> couponMap : couponList) {
						str.append(couponMap.get("couponName") + ",");
					}
					seller.setCouponMj(str.toString().substring(0,
							str.length() - 1));
				}
				
				seller.setPrice(seller.getPrice()/100);
				
				// 设置金币折扣信息
				SellerDiscount sellerDiscount = new SellerDiscount();
				sellerDiscount.setSellerInfoId(seller.getId());
				sellerDiscount.setNowNum(CommonUtils.getWeekNum());
				sellerDiscount.setNowTime(dateStr);
				SellerDiscount discountMap = sellerInfoService
						.getSellerDiscount(sellerDiscount);
				if (discountMap != null) {
					/*seller.setCouponJb("金币"
							+ CommonUtils.doubleTrans((double) discountMap
									.getGoldNum() / 100)
							+ "折,微信"
							+ CommonUtils.doubleTrans((double) discountMap
									.getWeixinNum() / 100)
							+ "折,支付宝"
							+ CommonUtils.doubleTrans((double) discountMap
									.getZfbNum() / 100) + "折");*/
					String str = "";
					if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
						BigDecimal goldNum = new BigDecimal(discountMap.getGoldNum());
						goldNum = goldNum.divide(new BigDecimal(10));
						str += "金币"+goldNum+"折，";
						//str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
					}
					if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
						BigDecimal wxNum = new BigDecimal(discountMap.getWeixinNum());
						wxNum = wxNum.divide(new BigDecimal(10));
						str += "微信"+wxNum+"折，";
						//str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
					}
					if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
						BigDecimal aliNum = new BigDecimal(discountMap.getZfbNum());
						aliNum = aliNum.divide(new BigDecimal(10));
						str += "支付宝"+aliNum+"折，";
						//str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
					}
					if(str.endsWith("，")){
						str = str.substring(0, str.length()-1);
					}
					seller.setCouponJb(str);
				}
				sellerAllList.add(seller);
			}

			infoMap.put("sellerList", sellerAllList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;

	}

	/**
	 * 模糊搜索商家信息(点击搜索按钮)
	 * 
	 * @param searchWord
	 *            关键字,xpoint x坐标,ypoint y坐标,pageNow 当前页数,pageSize 每页条数
	 * @author zq
	 */
	@RequestMapping(value = "/searchAllSeller")
	@ResponseBody
	public Object searchAllSeller(HttpServletRequest request,
			SellerInfo sellerInfo, int pageNow, int pageSize) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			if (StringUtils.isBlank(sellerInfo.getSearchWord())) {
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "请输入查询词");
				return infoMap;
			}

			// 点击搜索时候查询热搜索表,如果有一样热搜词则搜索次数加一,如果没有则新添
			//searchHotService.goSearchWord(sellerInfo.getSearchWord());

			Page<?> page = PageHelper.startPage(pageNow, pageSize);
			List<SellerInfo> sellerList = sellerInfoService.selectBySearch(sellerInfo);
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			String dateStr = sdf.format(d);
			
			List<HashMap<String, Object>> mapList = new ArrayList<HashMap<String, Object>>();
			
			for (SellerInfo seller : sellerList) {
				// 计算距离
				/*seller.setDistance(CommonUtils.contrastMap(
						sellerInfo.getXpoint(), sellerInfo.getYpoint(),
						seller.getXpoint(), seller.getYpoint()));
				// 计算价格
				seller.setPrice(seller.getPrice() / 100);
				// 设置类型为商家
				seller.setSearchType(Constants.SELLER_SEARCH_SELLER);
				// 设置优惠券信息
				List<HashMap<String, Object>> couponList = sellerInfoService
						.getSellerCoupons(seller.getId());
				if (couponList.size() > 0) {
					StringBuffer str = new StringBuffer();
					for (HashMap<String, Object> couponMap : couponList) {
						str.append(couponMap.get("couponName") + ",");
					}
					seller.setCouponMj(str.toString().substring(0,
							str.length() - 1));
				}
				// 设置金币折扣信息
				SellerDiscount sellerDiscount = new SellerDiscount();
				sellerDiscount.setSellerInfoId(seller.getId());
				sellerDiscount.setNowNum(CommonUtils.getWeekNum());
				sellerDiscount.setNowTime(dateStr);
				SellerDiscount discountMap = sellerInfoService
						.getSellerDiscount(sellerDiscount);
				if (discountMap != null) {
					seller.setCouponJb("金币买单"
							+ CommonUtils.doubleTrans((double) discountMap
									.getGoldNum() / 100)
							+ "折,微信买单"
							+ CommonUtils.doubleTrans((double) discountMap
									.getWeixinNum() / 100)
							+ "折,支付宝买单"
							+ CommonUtils.doubleTrans((double) discountMap
									.getZfbNum() / 100) + "折");
				}*/
				HashMap<String, Object> sellerMap = new HashMap<String, Object>();
				sellerMap.put("id", seller.getId());
				sellerMap.put("sellerName", seller.getSellerName());
				sellerMap.put("sellerScore", seller.getSellerScore() == null ? 0 : seller.getSellerScore());
				sellerMap.put("districtCode", seller.getDistrictCode());
				sellerMap.put("labels_id", seller.getLabelsId());
				sellerMap.put("price", seller.getPrice()/100);
				sellerMap.put("sellerLogo", StringUtils.isBlank(seller.getSellerHead()) ? "" : seller.getSellerHead() );
				sellerMap.put("imageSrc", StringUtils.isBlank(seller.getImageSrc()) ? "" : seller.getImageSrc() );
				sellerMap.put("distance", CommonUtils.contrastMap(
						sellerInfo.getXpoint(), sellerInfo.getYpoint(),
						seller.getXpoint(), seller.getYpoint()));
				sellerMap.put("labels_name", PeiniUtils.yetaiMap.get(seller.getLabelsId().toString()).getCodesName());
				sellerMap.put("districtName", PeiniUtils.distMap.get(seller.getDistrictCode()).getPlcaeName());
				// 设置优惠券信息
				List<HashMap<String, Object>> couponList = sellerInfoService.getSellerCoupons(seller.getId());
				if (couponList.size() > 0) {
					StringBuffer str = new StringBuffer();
					for (HashMap<String, Object> couponMap : couponList) {
						str.append(couponMap.get("couponName") + ",");
					}
					sellerMap.put("countMJ",str.toString().substring(0, str.length() - 1));
				}else{
					sellerMap.put("countMJ","");
				}
				
				// 设置金币折扣信息
				SellerDiscount sellerDiscount = new SellerDiscount();
				sellerDiscount.setSellerInfoId(seller.getId());
				sellerDiscount.setNowNum(CommonUtils.getWeekNum());
				sellerDiscount.setNowTime(dateStr);
				SellerDiscount discountMap = sellerInfoService.getSellerDiscount(sellerDiscount);
				if (discountMap != null) {
					String str = "";
					/*if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
						str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
					}
					if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
						str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
					}
					if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
						str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
					}*/
					
					if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
						BigDecimal goldNum = new BigDecimal(discountMap.getGoldNum());
						goldNum = goldNum.divide(new BigDecimal(10));
						str += "金币"+goldNum+"折，";
						//str += "金币"+((double)discountMap.getGoldNum())/10+"折，";
					}
					if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
						BigDecimal wxNum = new BigDecimal(discountMap.getWeixinNum());
						wxNum = wxNum.divide(new BigDecimal(10));
						str += "微信"+wxNum+"折，";
						//str += "微信"+((double)discountMap.getWeixinNum())/10+"折，";
					}
					if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
						BigDecimal aliNum = new BigDecimal(discountMap.getZfbNum());
						aliNum = aliNum.divide(new BigDecimal(10));
						str += "支付宝"+aliNum+"折，";
						//str += "支付宝"+((double)discountMap.getZfbNum())/10+"折，";
					}
					
					if(str.endsWith("，")){
						str = str.substring(0, str.length()-1);
					}
					sellerMap.put("countJB",str);
				} else {
					sellerMap.put("countJB", "");
				}
				
				// 设置金币折扣信息
				/*SellerDiscount sellerDiscount = new SellerDiscount();
				sellerDiscount.setSellerInfoId(seller.getId());
				sellerDiscount.setNowNum(CommonUtils.getWeekNum());
				sellerDiscount.setNowTime(dateStr);
				SellerDiscount discountMap = sellerInfoService
						.getSellerDiscount(sellerDiscount);
				if (discountMap != null) {
					String str = "";
					if(discountMap.getGoldNum() != null && discountMap.getGoldNum() != 100){
						str += "金币买单"+discountMap.getGoldNum()+"折，";
					}
					if(discountMap.getWeixinNum() != null && discountMap.getWeixinNum() != 100){
						str += "微信买单"+discountMap.getWeixinNum()+"折，";
					}
					if(discountMap.getZfbNum() != null && discountMap.getZfbNum() != 100){
						str += "支付宝买单"+discountMap.getZfbNum()+"折，";
					}
					if(str.endsWith("，")){
						str = str.substring(0, str.length()-1);
					}
					sellerMap.put("countJB",str);
				} else {
					sellerMap.put("countJB", "");
				}*/
				
				mapList.add(sellerMap);
			}

			infoMap.put("sellerList", mapList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;

	}

	/**
	 * 获取热门搜索词
	 * 
	 * @author zq
	 */
	@ResponseBody
	@RequestMapping(value = "/getHotWord")
	public Object getHotWord(HttpServletRequest request,
			@RequestParam(value="type",defaultValue="1") Integer type  //1商家；2地点；
			) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			Page<?> page = PageHelper.startPage(1,9);
			SearchHotExample example = new SearchHotExample();
			example.createCriteria().andTypeEqualTo(type);
			example.setOrderByClause("hot_num desc");
			List<SearchHot> wordList = searchHotMapper.selectByExample(example);
			infoMap.put("data", wordList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;

	}

	/**
	 * 热词搜索告知服务器接口
	 * @author Han Guohong
	 * @param request
	 * @param hotName
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/searchByHotWord")
	public Object searchByHotWord(HttpServletRequest request,
			@RequestParam(value="type",defaultValue="1") Integer type,  //1商家；2地点；
			@RequestParam(value = "hotName") String hotName) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		
		try {
			List<HashMap<String, String>> sellerList = new ArrayList<HashMap<String, String>>();
			/*if(type == 1){
				SellerInfoExample example = new SellerInfoExample();
				example.createCriteria().andSellerNameLike("%"+hotName+"%");
				List<SellerInfo> list = sellerInfoMapper.selectByExample(example);
				
				HashMap<String, String> map = new HashMap<String, String>();
				for (SellerInfo sellerInfo : list) {
					map.clear();
					map.put("sellerId", sellerInfo.getId().toString());
					map.put("sellerName", sellerInfo.getSellerName());
					map.put("sellerLnt", sellerInfo.getYpoint());
					map.put("sellerLat", sellerInfo.getXpoint());
					
					//TODO惠券后处理
					map.put("sellerDiscount", "0");
					map.put("sellerCoupon", "0");
					sellerList.add(map);
				}
				
				if(list.size()>0){
					SearchHot searchHot = new SearchHot();
					searchHot.setHotName(hotName);
					searchHot.setType(type);
					PeiniUtils.hotSearchList.add(searchHot);
				}
			}else{*/
				SearchHot searchHot = new SearchHot();
				searchHot.setHotName(hotName);
				searchHot.setType(type);
				PeiniUtils.hotSearchList.add(searchHot);
			//}
			
			//infoMap.put("data", sellerList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;

	}

	/**
	 * 插入商家入驻申请
	 * 
	 * @author zq
	 */
	@RequestMapping(value = "/sellerJoin")
	@ResponseBody
	public Object sellerJoin(
			HttpServletRequest request,
			@RequestParam(value = "userToken") String userToken,
			@RequestParam(value = "sellerProvince") Integer sellerProvince,
			@RequestParam(value = "sellerCity") Integer sellerCity,
			@RequestParam(value = "sellerName") String sellerName,
			@RequestParam(value = "sellerType") Integer sellerType,// 1企业；2个人',
			@RequestParam(value = "contactName") String contactName,
			@RequestParam(value = "contactPhone") String contactPhone) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {

			JSONObject obj = PeiniUtils.validToken(userToken);
			if (obj.getInteger("resultCode") != 1) {
				return obj;
			}
			String userId = obj.getString("userId");

			SellerJoin sell = new SellerJoin();
			sell.setSellerProvince(sellerProvince);
			sell.setSellerCity(sellerCity);
			sell.setSellerName(sellerName);
			sell.setContactName(contactName);
			sell.setSellerType(sellerType);
			sell.setContactName(contactName);
			sell.setContactPhone(contactPhone);
			sell.setRegtime(new Date());
			sell.setUserid(userId);

			sellerJoinService.insertBySellerJoin(sell);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}

		return infoMap;
	}

	/**
	 * 优惠买单店铺评价
	 * 
	 * @param sellerInfoId
	 *            店铺id,sellerServer 生活服务评分,sellerCondition 环境评分,sellerMeal
	 *            口味评分,orderId 订单id
	 * @author zq
	 */
	@RequestMapping(value = "/sellerJudge")
	@ResponseBody
	public Object sellerJudge(HttpServletRequest request,
			SellerJudge sellerJudge, Long orderId,
			@RequestParam(value="userId") String userId
			) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if (obj.getInteger("resultCode") != 1) {
				return obj;
			}
			userId = obj.getString("userId");
			
			SellerJudgeExample judgeExample = new SellerJudgeExample();
			judgeExample.createCriteria().andOrderIdEqualTo(orderId);
			Integer cnt = sellerJudgeMapper.countByExample(judgeExample);
			if(cnt>0){
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "该订单已经评价过了，不允许重复评价");
				return infoMap;
			}
			sellerJudgeService.sellerJudge(sellerJudge,orderId,userId);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}

	/**
	 * 任务买单店铺和用户评价
	 * 
	 * @param orderId
	 *            订单id
	 * @param sellerInfoId
	 *            店铺id,taskId 任务id,sellerServer 生活服务评分,sellerCondition
	 *            环境评分,sellerMeal 口味评分
	 * @param userId
	 *            评价人id,otherUserId 被评价人id,userLife 生活品味评分,userImage
	 *            形象评分,userDate 交往评分,gold 打赏金币(金币乘以100)
	 * @author zq
	 */
	@RequestMapping(value = "/sellerAndUserJudge")
	@ResponseBody
	public Object sellerAndUserJudge(HttpServletRequest request,
			SellerJudge sellerJudge, UserJudge userJudge, /*Double gold,*/
			Integer taskId, Long orderId) {
		sellerJudge.setTaskInfoId(taskId);
		userJudge.setTaskInfoId(taskId);
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			sellerJudge.setTaskInfoId(taskId);
			userJudge.setTaskInfoId(taskId);
			JSONObject obj = PeiniUtils.validToken(userJudge.getUserId());
			if (obj.getInteger("resultCode") != 1) {
				return obj;
			}
			String userId = obj.getString("userId");
			userJudge.setUserId(userId);
			
			TaskInfo taskInfo = taskInfoMapper.selectByPrimaryKey(taskId);
			if(taskInfo.getUserId().equals(userId)){
				if(taskInfo.getTaskStatus() == 4){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "该订单已经评价过了，不允许重复评价");
					return infoMap;
				}
			}else if(taskInfo.getOtherUserId().equals(userId)){
				if(taskInfo.getTaskOtherStatus() == 41){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "该订单已经评价过了，不允许重复评价");
					return infoMap;
				}
			}
			sellerJudgeService.sellerAndUserJudge(sellerJudge, userJudge, taskId, orderId);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}

	/**
	 * (关闭/开启店铺)
	 * 
	 * @param id
	 *            店铺id;status 0 关闭 1 开启;
	 * @author zq
	 */
	@RequestMapping(value = "/updateSellerStatus")
	@ResponseBody
	public Object updateSellerStatus(HttpServletRequest request,
			SellerInfo sellerInfo) {
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			infoMap=sellerInfoService.updateByStatus(sellerInfo);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}

		return infoMap;
	}
}
